<template>
	<view class="main-page">
		<u-loading-page :loading="loadding" loading-mode="semicircle" loading-text="加载中"></u-loading-page>
		<view class="main" v-if="!loadding">
			<view class="banner_box">
				<u-swiper :list="bannerList" keyName="url" height="180" @click="bannerClick"></u-swiper>
				<view class="message" style="display: flex; justify-content: space-between;">
					<view class=""></view>
					<message :color="'#fff'" :read="read"></message>
				</view>
				<view v-if="dataTotal.earnings && userinfo.IOS_set == 1" class="earnings">
					<view class="items">
						<view class="vals" @click="earningsClick(2)">
							<text>{{dataTotal.earnings.day}}</text>
						</view>
						<view class="title" @click="earningsClick(2)">
							<text>今日收益</text>
						</view>
					</view>
					<view class="items">
						<view class="vals" @click="earningsClick(1)">
							<text>{{dataTotal.earnings.month}}</text>
						</view>
						<view class="title" @click="earningsClick(1)">
							<text>本月收益</text>
						</view>
					</view>
				</view>
				<view v-else class="earnings">
					<view class="items">
						<view class="vals" @click="earningsClick(2)">
							<text>{{dataTotal.trade.day}}</text>
						</view>
						<view class="title" @click="earningsClick(2)">
							<text>今日交易</text>
						</view>
					</view>
					<view class="items">
						<view class="vals" @click="earningsClick(1)">
							<text>{{dataTotal.trade.month}}</text>
						</view>
						<view class="title" @click="earningsClick(1)">
							<text>本月交易</text>
						</view>
					</view>
				</view>
			</view>
			<view class="datas" style="display: none;">
				<view class="title">
					<text>交易</text>
				</view>
				<view v-if="dataTotal.trade" class="lists">
					<view class="item" @click="pathTos(1,1)">
						<view class="top">
							<text>{{dataTotal.trade.day}}</text>
						</view>
						<view class="bottom">
							<text>今日</text>
						</view>
					</view>
					<view class="item" @click="pathTos(1,2)">
						<view class="top">
							<text>{{dataTotal.trade.month}}</text>
						</view>
						<view class="bottom">
							<text>本月</text>
						</view>
					</view>
				</view>
			</view>
			<view class="actives">
				<view class="title">
					<text>激活</text>
				</view>
				<view v-if="dataTotal.active" class="lists">
					<view class="item" @click="pathTos(2,1)">
						<view class="top">
							<text>{{dataTotal.active.day}}</text>
						</view>
						<view class="bottom">
							<text>今日</text>
						</view>
					</view>
					<view class="item" @click="pathTos(2,2)">
						<view class="top">
							<text>{{dataTotal.active.month}}</text>
						</view>
						<view class="bottom">
							<text>本月</text>
						</view>
					</view>
				</view>
			</view>
			<view class="menu">
				<view class="title">
					<text>业务功能</text>
				</view>
				<view class="lists">
					<view class="items" v-for="(item, index) in menuData" :key="index" @click="pathTo(item.path)">
						<image class="img" :src="src + item.icons" mode="aspectFit"></image>
						<text>{{item.name}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var util = require('@/util/request.js');
	import message from '@/component/message.vue'
	export default {
		data() {
			return {
				loadding: false,
				menuData: [],
				src: '',
				userinfo: {},
				dataTotal: {
					active: {
						day: 0,
						month: 0
					},
					earnings: {
						day: '0.00',
						month: '0.00'
					},
					trade: {
						day: '0.00',
						month: '0.00'
					}
				},
				bannerList: [],
				read: 0,
			}
		},
		components: {
			message
		},
		onLoad() {
			this.userinfo = uni.getStorageSync('userinfo')
			this.src = util.API_URL
			this.getBanner()
		},
		onShow() {
			this.getMenu()
			this.getHzyIndexData()
			this.getNoReadMessage()
		},
		methods: {
			// 菜单点击
			pathTo(path) {
				uni.navigateTo({
					url: path
				})
			},
			// 数据点击
			pathTos(cid, tid) {
				var path = '/pages/hzy/data/trade/index'
				if (cid == 2) {
					path = '/pages/hzy/data/active/index'
				}
				uni.navigateTo({
					url: path + '?type=' + tid
				})
			},
			// 获取banner图
			async getBanner() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getHzyBanner'
				});
				uni.hideLoading()
				this.loadding = false
				if (res.code == 200) {
					this.bannerList = res.data
				}
			},
			// 菜单展示
			async getMenu() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'menu/getMenu',
					data: {
						type: 0,
						class: 2
					}
				});
				uni.hideLoading()
				this.loadding = false
				if (res.code == 200) {
					this.menuData = res.data
				}
			},
			// 数据统计
			async getHzyIndexData() {
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getHzyIndexData'
				});
				if (res.code == 200) {
					this.dataTotal = res.data
				}
			},
			// 收益详情
			earningsClick(type) {
				uni.navigateTo({
					url: '/pages/hzy/cash/total/detail?type=' + type
				})
			},
			// banner图点击
			bannerClick(index) {
				if (this.bannerList[index].is_links == 2) {
					uni.navigateTo({
						url: '/pages/hzy/article/index?id=' + this.bannerList[index].id
					})
				}
			},
			// 获取未读信息
			async getNoReadMessage() {
				const {
					data: res
				} = await this.$myHttp({
					url: 'setting/getNoReadMessage'
				});
				if (res.code == 200) {
					this.read = res.data
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.main-page {
		.main {
			
			.banner_box {
				position: relative;
				
				.message {
					position: absolute;
					top: 0;
					right: 0;
				}
				
				.earnings {
					width: 100%;
					position: absolute;
					display: flex;
					align-items: center;
					bottom: 20rpx;
					z-index: 99999;
					
					.items {
						text-align: center;
						width: 50%;
						color: #FFFFFF;
						font-weight: bold;
						
						.vals {
							font-size: 36rpx;
						}
						
						.title {
							font-size: 26rpx;
						}
					}
				}
			}
			
			.menu {
				margin: 0 30rpx;
				margin-top: 30rpx;
				margin-bottom: 30rpx;
				background-color: #FFFFFF;
				box-shadow: 7px 0px 30px -18px #888888;
				padding: 20rpx;
				border-radius: 16rpx;

				.title {
					padding: 10rpx 20rpx;
					border-left: 10rpx solid #2979ff;
					font-weight: bold;
					border-bottom: 1px solid #f4f4f5;
				}

				.lists {
					padding-top: 30rpx;
					display: flex;
					align-items: center;
					flex-wrap: wrap;

					.items {
						margin-bottom: 40rpx;
						display: flex;
						flex-direction: column;
						align-items: center;
						min-width: 25%;

						.img {
							width: 80rpx;
							height: 80rpx;
							margin-bottom: 10rpx;
						}

						text {
							font-size: 28rpx;
						}
					}
				}
			}

			.datas {
				margin: 0 30rpx;
				margin-top: 40rpx;
				background-color: #FFFFFF;
				box-shadow: 7px 0px 30px -18px #888888;
				background: url('../../static/hzy_trade.jpg') no-repeat center;
				background-size: 100% 100%;
				padding: 20rpx;
				border-radius: 16rpx;

				.title {
					padding: 10rpx 20rpx;
					border-left: 10rpx solid #19be6b;
					font-weight: bold;
					border-bottom: 1px solid #f4f4f5;
				}

				.lists {
					padding: 10rpx 0;
					display: flex;
					align-items: center;
					flex-wrap: wrap;

					.item {
						display: flex;
						flex-direction: column;
						align-items: center;
						min-width: 49%;
						font-weight: bold;

						.top {
							margin-bottom: 20rpx;
							font-size: 36rpx;
						}
						
						.bottom {
							font-size: 26rpx;
						}
					}

					.item:nth-child(1) {
						border-right: 1px dashed #c8c9cc;
					}
				}
			}

			.actives {
				margin: 0 30rpx;
				margin-top: 30rpx;
				background-color: #FFFFFF;
				box-shadow: 7px 0px 30px -18px #888888;
				background: url('../../static/hzy_active.png') no-repeat center;
				background-size: 100% 100%;
				padding: 20rpx;
				border-radius: 16rpx;

				.title {
					padding: 10rpx 20rpx;
					border-left: 10rpx solid #f4f4f5;
					font-weight: bold;
					border-bottom: 1px solid #f4f4f5;
				}

				.lists {
					padding: 10rpx 0;
					display: flex;
					align-items: center;
					flex-wrap: wrap;

					.item {
						display: flex;
						flex-direction: column;
						align-items: center;
						min-width: 49%;
						font-weight: bold;

						.top {
							margin-bottom: 20rpx;
							font-size: 36rpx;
						}
						
						.bottom {
							font-size: 26rpx;
						}
					}

					.item:nth-child(1) {
						border-right: 1px dashed #c8c9cc;
					}
				}
			}
		}
	}
</style>